from rest_framework import serializers

from six_it.models import Article, User


class UserArticle(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = ['id', 'title']


class UserSerializers(serializers.ModelSerializer):
    articles = UserArticle(read_only=True, many=True)

    class Meta:
        model = User
        fields = ['id', 'username', 'avatar', 'articles', 'fans']


class ArticleInfoSerializer(serializers.ModelSerializer):
    user = UserSerializers(read_only=True)

    # collected = serializers.BooleanField(source='collected_users')

    class Meta:
        model = Article
        fields = ['id', 'title', 'content', 'createtime', 'user', 'collected_users', 'image']
